package com.iknow.xmpp.service;

import android.os.Handler;
import com.iknow.IKnow;
import com.iknow.util.Loger;

public class ConnectionMonitorThread extends Thread
{
  public static int ACTION_RECONNECT = 0;
  public static final int HANDLER_RECONNECT = 1;
  private static final String TAG = "ConnectionMonitorThread";
  private IKnow mApp;
  private Handler mHandler;
  private int mNextTime;
  private int mReConnectCount;
  private boolean mTerminated = false;

  public ConnectionMonitorThread(Handler paramHandler, IKnow paramIKnow)
  {
    this.mHandler = paramHandler;
    this.mApp = paramIKnow;
    setDaemon(true);
  }

  // ERROR //
  public void run()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 31	com/iknow/xmpp/service/ConnectionMonitorThread:mTerminated	Z
    //   4: istore_3
    //   5: iload_3
    //   6: ifeq +8 -> 14
    //   9: aload_0
    //   10: invokevirtual 45	com/iknow/xmpp/service/ConnectionMonitorThread:shutdown	()V
    //   13: return
    //   14: aload_0
    //   15: getfield 35	com/iknow/xmpp/service/ConnectionMonitorThread:mApp	Lcom/iknow/IKnow;
    //   18: invokevirtual 51	com/iknow/IKnow:isConnected	()Z
    //   21: ifne +23 -> 44
    //   24: aload_0
    //   25: getfield 33	com/iknow/xmpp/service/ConnectionMonitorThread:mHandler	Landroid/os/Handler;
    //   28: iconst_1
    //   29: invokevirtual 57	android/os/Handler:obtainMessage	(I)Landroid/os/Message;
    //   32: astore 4
    //   34: aload_0
    //   35: getfield 33	com/iknow/xmpp/service/ConnectionMonitorThread:mHandler	Landroid/os/Handler;
    //   38: aload 4
    //   40: invokevirtual 61	android/os/Handler:sendMessage	(Landroid/os/Message;)Z
    //   43: pop
    //   44: aload_0
    //   45: iconst_1
    //   46: aload_0
    //   47: getfield 63	com/iknow/xmpp/service/ConnectionMonitorThread:mReConnectCount	I
    //   50: iadd
    //   51: putfield 63	com/iknow/xmpp/service/ConnectionMonitorThread:mReConnectCount	I
    //   54: aload_0
    //   55: getfield 63	com/iknow/xmpp/service/ConnectionMonitorThread:mReConnectCount	I
    //   58: bipush 6
    //   60: if_icmpge +43 -> 103
    //   63: aload_0
    //   64: sipush 10000
    //   67: aload_0
    //   68: getfield 65	com/iknow/xmpp/service/ConnectionMonitorThread:mNextTime	I
    //   71: iadd
    //   72: putfield 65	com/iknow/xmpp/service/ConnectionMonitorThread:mNextTime	I
    //   75: aload_0
    //   76: getfield 65	com/iknow/xmpp/service/ConnectionMonitorThread:mNextTime	I
    //   79: i2l
    //   80: invokestatic 69	com/iknow/xmpp/service/ConnectionMonitorThread:sleep	(J)V
    //   83: goto -83 -> 0
    //   86: astore_2
    //   87: ldc 13
    //   89: aload_2
    //   90: invokevirtual 73	java/lang/Exception:getMessage	()Ljava/lang/String;
    //   93: invokestatic 79	com/iknow/util/Loger:e	(Ljava/lang/String;Ljava/lang/String;)V
    //   96: aload_0
    //   97: invokevirtual 45	com/iknow/xmpp/service/ConnectionMonitorThread:shutdown	()V
    //   100: goto -87 -> 13
    //   103: aload_0
    //   104: iconst_2
    //   105: aload_0
    //   106: getfield 65	com/iknow/xmpp/service/ConnectionMonitorThread:mNextTime	I
    //   109: imul
    //   110: putfield 65	com/iknow/xmpp/service/ConnectionMonitorThread:mNextTime	I
    //   113: goto -38 -> 75
    //   116: astore_1
    //   117: aload_0
    //   118: invokevirtual 45	com/iknow/xmpp/service/ConnectionMonitorThread:shutdown	()V
    //   121: aload_1
    //   122: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   0	5	86	java/lang/Exception
    //   14	83	86	java/lang/Exception
    //   103	113	86	java/lang/Exception
    //   0	5	116	finally
    //   14	83	116	finally
    //   87	96	116	finally
    //   103	113	116	finally
  }

  public void shutdown()
  {
    this.mTerminated = true;
    Loger.i("ConnectionMonitorThread", "iKnow xmpp ConnectionMonitorThread close");
  }

  public void startThread()
  {
    if (isAlive())
      return;
    this.mNextTime = 1000;
    try
    {
      start();
      Loger.i("ConnectionMonitorThread", "iKnow xmpp ConnectionMonitorThread start");
    }
    catch (IllegalThreadStateException localIllegalThreadStateException)
    {
      Loger.e("ConnectionMonitorThread", localIllegalThreadStateException.getMessage());
    }
  }
}